package me.zk.practice1.hw;

import java.util.*;

/**
 * @author zhangkai
 * @date 2023/8/7 11:42
 */
public class HWBJ29 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int index = Integer.parseInt(scanner.nextLine());

        int len = Integer.parseInt(scanner.nextLine());

        String[] strs = new String[len];
        Map<Character, List<String>> map = new HashMap<>();
        for (int i = 0; i < len; i++) {
            strs[i] = scanner.nextLine();
            if (i != index) {
                char c = strs[i].charAt(0);
                List<String> list = map.getOrDefault(c,new ArrayList<String>());
                list.add(strs[i]);
                map.put(c,list);
            }

        }
        for(Character c : map.keySet()) {
            map.get(c).sort(new Comparator<String>() {
                @Override
                public int compare(String o1, String o2) {
                    if (o1.length() > o2.length()) {
                        return -1;
                    } else if (o1.length() == o2.length()) {
                        int i = 1;
                        int c = 0;
                        while (i < o1.length()) {
                            if (o1.charAt(i) > o2.charAt(i)) {
                                c = 1;
                                break;
                            } else if (o1.charAt(i) == o2.charAt(i)) {
                                i++;
                            } else {
                               c = -1;
                               break;
                            }
                        }
                        return c;
                    } else {
                        return 0;
                    }
                }
            });

        }

        StringBuffer sb = new StringBuffer();
        sb.append(strs[index]);

        while (map.containsKey(sb.charAt(sb.length()-1))) {
            List<String> list = map.get(sb.charAt(sb.length()-1));
            if (list.size() == 0) {
                break;
            } else {
                sb.append(list.get(0));
                list.remove(0);
            }

        }
        System.out.println(sb);

    }
}
